<template>
  <div class="app-container">
    <el-form ref="queryRef" :model="queryParams" :inline="true">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="全部"
          clearable
          style="width: 150px"
          @keyup.enter="handleQuery"
          />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
            v-model="queryParams.phone"
            placeholder="全部"
            clearable
            style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="证件号" prop="idcCode">
        <el-input
            v-model="queryParams.idcCode"
            placeholder="全部"
            clearable
            style="width: 250px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--表格数据-->
    <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" width="80" align="center"/>
      <el-table-column label="姓名" prop="realName" min-width="100" align="center"/>
      <el-table-column label="性别" prop="sexStr" min-width="50" align="center"/>
      <el-table-column label="手机号" prop="phone" min-width="130" align="center"/>
      <el-table-column label="出生日期" prop="birth" min-width="130" align="center"/>
      <el-table-column label="证件类型" prop="idcTypeStr" min-width="50" align="center"/>
      <el-table-column label="证件号码" prop="idcCode" min-width="100" align="center"/>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding">
        <template #default="scope">
          <el-button type="text" @click="goAddTrainList(trainId,scope.row)">添加报名</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="total > 0"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        :total="total"
        @pagination="getList"
    />

  </div>
</template>

<script setup name="addPerson">

import {getCurrentInstance, ref} from 'vue'
import {onMounted, reactive} from '@vue/runtime-core'
import {toRefs} from '@vueuse/shared'
import {addPersonList} from '../../../../../api/train/verity'
import {useRouter} from 'vue-router'
import { useRoute } from 'vue-router'
const route = useRoute()
const router = useRouter()

const {proxy} = getCurrentInstance()



const tableData = ref([])
const total = ref(0)
const loading = ref(true)
const trainId = route.params.trainId
const dialogPropsBase = {
  open: false,
  title: '',
  data: null
}

const data = reactive({
  form: {},
  queryParams:{
    pageNum: 1,
    pageSize: 10,
    trainId:trainId,
    name: undefined,
    phone: undefined,
    idcCode: undefined
  },
  rules:{}
})

const dialogAddTrainsProps = ref({
  ...dialogPropsBase
})

const {queryParams,form, rules} = toRefs(data)

//获取列表
function getList(){
  loading.value = true
  addPersonList(queryParams.value).then(res => {
    loading.value = false
    tableData.value = res.rows
    total.value = res.total
  })
}

function handleQuery(){
  queryParams.value.pageNum = 1
  queryParams.value.trainId = trainId
  getList()
}

function resetQuery(){
  proxy.resetForm('queryRef')
  handleQuery()
}

//添加报名
function goAddTrainList(trainId,row){
  router.push({name:"addTrainList",params:{trainId:trainId,userId:row.userId}})
}


onMounted(()=>{
  getList()
})


</script>

<style scoped>

</style>
